import java.util.Map;
import java.util.Random;
import java.util.Scanner;
/**
 * @Author 12629
 * @Date 2022/4/23 14:32
 * @Description：
 */

public class Test {


    /**
     * 求n的阶乘
     * @param n
     * @return
     */
    public static int fac(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }

    /**
     * 求1！+2！+......+k！
     * @param k
     * @return
     */
    public static int facSum(int k) {
        int sum = 0;
        for (int i = 1; i <= k; i++) {
            sum += fac(i);
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(facSum(5));
    }

    //maxNum
    public static int add (int a,int b) {
        System.out.println("正在调用add()");
        return a+b;
    }

    public static void main21(String[] args) {
        int a = 10;
        int b = 20;
        int ret = add(a, b);
        System.out.println("ret = " + ret);
    }
    public static void main20(String[] args) {
        //func();
        //int ret = func();
        //System.out.println(ret);
        int a = 10;
        int b = 20;
        System.out.println("第一次调用方法之前");
        int ret = add(a, b);
        System.out.println("第一次调用方法之后");
        System.out.println("ret = " + ret);
        System.out.println("第二次调用方法之前");
        ret = add(30, 50);
        System.out.println("第二次调用方法之后");
        System.out.println("ret = " + ret);
    }



    public static void func() {
        System.out.println(3);
    }





    //1、参数的个数必须匹配
    //2、参数的类型必须匹配
    //3、参数的顺序必须匹配
    public static void main19(String[] args) {
        int x = 1;
        int y = 2;
        int ret = add(x,y);
        System.out.println(ret);

        int z = 10;
        int k = 20;
        int ret2 = add(z,k);
        System.out.println(ret2);
    }


    public static void main18(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int randNum = random.nextInt(101);//[0,101)==>[0,100]
        System.out.println("随机数是"+randNum);

        //int randNum = random.nextInt(100)+1;//[1,101)  数学的思维：50-100
        // int rand = (int) Math.random();TODO::1、查一下这个如何生成一个随机数
        //int randNum = random.nextInt();TODO:: 2、不给数字 生成的随机数是哪个范围？？
        while (true) {
            System.out.println("请输入你要猜的数字：");
            int num = scanner.nextInt();
            if(num < randNum) {
                System.out.println("猜小了！");
            }else if(num == randNum) {
                System.out.println("猜对了！");
                break;
            }else {
                System.out.println("猜大了！");
            }
        }

    }

    public static void main16(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入你的姓名：");
        String str = scanner.nextLine();
        System.out.println(str);

        System.out.println("请输入你的年龄：");
        int age = scanner.nextInt();
        System.out.println(age);

        System.out.println("请输入你的工资：");
        float money = scanner.nextFloat();
        System.out.println(money);
    }

    public static void main15(String[] args) {
        System.out.println("输出且换行！");
        System.out.print("输出且不换行！");
        System.out.printf("%s\n","真的没换行吗?");
    }

    public static void main14(String[] args) {
        /*while (true) {
            System.out.println("fdsafa");
        }*/
        /*for(;true;) {
            System.out.println("fdafa");
        }*/

        for(;;) {
            System.out.println("fdafa");
        }
    }

    public static void main13(String[] args) {
        int i = 0;
        do {
            System.out.println("fhaha!");
        }while (i != 0);
    }

    public static void main12(String[] args) {
        int sum = 0;
        for (int j = 1; j <= 5; j++) {
            int ret = 1;
            for (int i = 1; i <= j; i++) {
                ret *= i;
            }
            sum += ret;
        }
        System.out.println(sum);
    }

    /**
     * 求5的阶乘
     * @param args
     */
    public static void main11(String[] args) {
        int ret = 1;
        for (int i = 1; i <= 5; i++) {
            ret *= i;
        }
        System.out.println(ret);
    }

    public static void main10(String[] args) {
        for (int i = 1; i <= 10; i++) {
            System.out.println(i);
        }
    }
    public static void main9(String[] args) {
        //找到1-100之间  既是3的倍数  也是5的倍数的所有的数据【continue】
        int i = 1;
        while (i <= 100) {
            if(i % 15 != 0) {
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }

    public static void main8(String[] args) {
        int i = 1;
        while (i <= 10) {
            if(i == 2){
                i++;
                continue;
            }
            System.out.println("hello");
            i++;
        }
    }


    /**
     * 求5的阶乘的和=1！+2！+3！+4！+5！
     * @param args
     */
    public static void main7(String[] args) {
        int j = 1;
        int sum = 0;
        while (j <= 5) {
            int i = 1;
            int ret = 1;
            while (i <= j) {
                ret = ret * i;
                i++;
            }
            sum += ret;
            j++;
        }
        System.out.println(sum);
    }

    /**
     * 求了一个5的阶乘
     * @param args
     */
    public static void main6(String[] args) {
        int i = 1;
        int ret = 1;
        while (i <= 5) {
            ret = ret * i;
            i++;
        }
        System.out.println(ret);
    }

    public static void main5(String[] args) {
        int sum = 0;//保存1-100的和
        int sumEve = 0;//保存1-100偶数的和
        int sumOdd = 0;//保存1-100奇数的和

        int i = 1;
        while (i <= 100) {
            sum += i;
            i++;
        }
        i = 2;//重新要赋值  上面已经加到了101了
        while (i <= 100) {
            sumEve += i;
            i+=2;//这里的步进  不仅仅是i++;
        }
        i = 1;
        while (i <= 100) {
            sumOdd += i;
            i+=2;//这里的步进  不仅仅是i++;
        }
        System.out.println(sum);
        System.out.println(sumEve);
        System.out.println(sumOdd);

    }
    public static void main4(String[] args) {
        int i = 1;//初始化一个数据
        while(i <= 3) {
            System.out.println(i);
            i++;
        }
    }

    /**
     * 面试问题：不能做switch的参数的类型有哪些？
     * long   float   double   boolean
     * @param args
     */
    public static void main3(String[] args) {
        String  a = "hello";//字符串是可以的  以后学习的枚举也是可以的
        //int a = 10;
        switch (a) {
            case "hello":
                System.out.println("hello");
                break;
            case "hello2":
                System.out.println("2");
                break;
            default:
                System.out.println("输入错误！");
                break;
        }
    }


    public static void main2(String[] args) {
        int x = 10;
        int y = 10;
        if (x == 20) {
            if (y == 10) {
                System.out.println("aaa");
            }else {
                System.out.println("bbb");
            }
        }
        /*System.out.println("fafaafa");
        System.out.println("fafaafa");
        System.out.println("fafaafa");
        System.out.println("fafaafa");*/
    }


    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        //处理循环输入
        while (scan.hasNextInt()) {
            int year = scan.nextInt();
            if (year % 100 == 0) {
                if (year % 400 == 0) {
                    System.out.println(year + "是闰年！");
                } else {
                    System.out.println(year + "不是闰年！");
                }
            } else {
                if (year % 4 == 0) {
                    System.out.println(year + "是闰年！");
                } else {
                    System.out.println(year + "不是闰年！");
                }
            }
        }
    }

}
